package com.muyu.danmo.service.impl;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoInformationShopping;
import com.muyu.danmo.mapper.DanmoInformationShoppingMapper;
import com.muyu.danmo.service.IDanmoInformationShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 个人信息名家推荐Service业务层处理
 * 
 * @author kunzong
 * @date 2024-12-11
 */
@Service
public class DanmoInformationShoppingServiceImpl implements IDanmoInformationShoppingService
{
    @Autowired
    private DanmoInformationShoppingMapper danmoInformationShoppingMapper;

    /**
     * 查询个人信息名家推荐
     * 
     * @param id 个人信息名家推荐主键
     * @return 个人信息名家推荐
     */
    @Override
    public DanmoInformationShopping selectDanmoInformationShoppingById(Long id)
    {
        return danmoInformationShoppingMapper.selectDanmoInformationShoppingById(id);
    }

    /**
     * 查询个人信息名家推荐列表
     * 
     * @param danmoInformationShopping 个人信息名家推荐
     * @return 个人信息名家推荐
     */
    @Override
    public List<DanmoInformationShopping> selectDanmoInformationShoppingList(DanmoInformationShopping danmoInformationShopping)
    {
        return danmoInformationShoppingMapper.selectDanmoInformationShoppingList(danmoInformationShopping);
    }

    /**
     * 新增个人信息名家推荐
     * 
     * @param danmoInformationShopping 个人信息名家推荐
     * @return 结果
     */
    @Override
    public Result insertDanmoInformationShopping(DanmoInformationShopping danmoInformationShopping)
    {
        DanmoInformationShopping danmoInformationShopping1 = new DanmoInformationShopping();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser==null){
            return Result.notLoggedIn("请登录");
        }
        danmoInformationShopping1.setUserId(loginUser.getUserid());
        danmoInformationShopping1.setShoppingId(danmoInformationShopping.getShoppingId());
        if (danmoInformationShoppingMapper.selectDanmoInformationShoppingList(danmoInformationShopping1)!=null){
            return Result.error("已收藏");
        }
        danmoInformationShopping.setCreateTime(DateUtils.getNowDate());
        danmoInformationShoppingMapper.insertDanmoInformationShopping(danmoInformationShopping);
        return Result.success(danmoInformationShopping,"添加成功");
    }

    /**
     * 修改个人信息名家推荐
     * 
     * @param danmoInformationShopping 个人信息名家推荐
     * @return 结果
     */
    @Override
    public int updateDanmoInformationShopping(DanmoInformationShopping danmoInformationShopping)
    {
        danmoInformationShopping.setUpdateTime(DateUtils.getNowDate());
        return danmoInformationShoppingMapper.updateDanmoInformationShopping(danmoInformationShopping);
    }

    /**
     * 批量删除个人信息名家推荐
     * 
     * @param ids 需要删除的个人信息名家推荐主键
     * @return 结果
     */
    @Override
    public int deleteDanmoInformationShoppingByIds(Long[] ids)
    {
        return danmoInformationShoppingMapper.deleteDanmoInformationShoppingByIds(ids);
    }

    /**
     * 删除个人信息名家推荐信息
     * 
     * @param id 个人信息名家推荐主键
     * @return 结果
     */
    @Override
    public int deleteDanmoInformationShoppingById(Long id)
    {
        return danmoInformationShoppingMapper.deleteDanmoInformationShoppingById(id);
    }
}
